package com.shujia.rec.util;

import com.shujia.util.Config;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtil {

    private static JedisPool jedisPool;

    static {

        //连接池配置
        JedisPoolConfig poolConfig = new JedisPoolConfig();

        //最大连接数据
        poolConfig.setMaxTotal(20);
        //最大空闲连接数据
        poolConfig.setMaxIdle(5);

        //超时时间
        poolConfig.setMaxWaitMillis(1000);

        jedisPool = new JedisPool(poolConfig, Config.getString("redis.host"), 6379);

    }

    //获取redis连接
    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
